﻿Imports System.Text
Imports System.DataExecutorServices
Imports System.Data.SqlClient
Imports Microsoft.SqlServer.Management.Smo
Imports Microsoft.SqlServer.Management.Common
Imports Demo.Data.Objects
Imports System.Reflection
Imports System.Aspect

Module ConsoleDemo

    Private ForAssy As Assembly

    Public Sub DoConsoleDemo(ByVal Assy As Assembly)
        ForAssy = Assy
        Trace.Listeners.Add(New ConsoleTraceListener)
        ListInfo()
        ExecuteProcs()
        If System.Diagnostics.Debugger.IsAttached Then Console.ReadKey()
    End Sub

    Private Sub ListInfo()
        Console.WriteLine("listing public verbs...")
        For Each aspv As Verb In GetVerbs(ForAssy, True)
            Console.WriteLine(aspv.Verb.UIName)
        Next
        Console.WriteLine()
    End Sub

    Private Sub ExecuteProcs()

        'TODO: translate these into proper tests

        Console.WriteLine("adding products")
        Dim p1 As IProductInfo = Product.GetNew("Product 1")
        Dim p2 As IProductInfo = Product.GetNew("Product 2")
        Dim p3 As IProductInfo = Product.GetNew("Product 3")
        p3.DeleteThisProduct()
        Dim ps() As IProductInfo = Product.GetAll()
        Console.WriteLine()

        Console.WriteLine("adding customers")
        Dim c1 As ICustomerInfo = Customer.GetNew("New Customer 1")
        Dim c2 As ICustomerInfo = Customer.GetNew("New Customer 2")
        Dim c3 As ICustomerInfo = Customer.GetNew("New Customer 3")
        c3.DeleteThisCustomer()
        Dim cs() As ICustomerInfo = Customer.GetAll()
        Console.WriteLine()

        Console.WriteLine("adding sales orders")
        Dim s1 As ISalesOrderInfo = c1.AddSalesOrder(Now)
        Dim s2 As ISalesOrderInfo = c1.AddSalesOrder(Now)
        Dim s3 As ISalesOrderInfo = c2.AddSalesOrder(Now)
        s3.DeleteThisSalesOrder()
        Dim ss() As ISalesOrderInfo = SalesOrder.GetAll()
        Console.WriteLine()

        Console.WriteLine("adding sales order lines")
        Dim sl1 As ISalesOrderLineInfo = s1.AddSalesOrderLine(p1, 0.3D)
        Dim sl2 As ISalesOrderLineInfo = s1.AddSalesOrderLine(p2, 5.8D)
        Dim sl3 As ISalesOrderLineInfo = s2.AddSalesOrderLine(p2, 17.4D)
        sl3.DeleteThisSalesOrderLine()
        Dim sls() As ISalesOrderLineInfo = SalesOrderLine.GetAll()
        Console.WriteLine()

        Console.WriteLine("getting sales order line DTO-style objects")
        Dim slDTOs() As ISalesOrderLineFullInfo = SalesOrderLine.GetAllWithFullInfo()

    End Sub

End Module
